package com.jacobson.huobi.utils;

import android.os.Environment;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class LogcatUtil {
    public static File getLogcatInfo(String fileName){
        File file = null;

        try {
            file = new File(Environment.getExternalStorageDirectory().getCanonicalPath() + "/" +fileName + "_log.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
//            Process process = null;
//            FileWriter fileWriter = null;
//            try {
//                ArrayList<String> commandLine = new ArrayList<String>();
//                commandLine.add("logcat");
//                commandLine.add("-d");
//
////            commandLine.add("*:E"); // 过滤所有的错误信息
////            commandLine.add("*:v , *:d , *:w , *:e , *:f , *:s "); // 过滤所有的错误信息
//
//                ArrayList<String> clearLog = new ArrayList<String>();  //设置命令  logcat -c 清除日志
//                clearLog.add("logcat");
//                clearLog.add("-c");
//
//                process = Runtime.getRuntime().exec(commandLine.toArray(new String[commandLine.size()]));
//                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
//                fileWriter = new FileWriter(file);
//                String line = null;
//                while ((line = bufferedReader.readLine()) != null) {
//
//                    fileWriter.append(line);
//                    fileWriter.flush();
//                }
//                fileWriter.close();
//                bufferedReader.close();
//            } catch (Exception ex) {
//                if (process != null) {
//                    process.destroy();
//                }
//                if (fileWriter != null) {
//                    fileWriter.close();
//                }
//            }
        }catch (Exception e) {
            return null;
        }
        return file;
    }
}
